package cn.com.tiptop.util.log;

import java.util.Properties;

import org.apache.log4j.PropertyConfigurator;

import cn.com.tiptop.util.MyResource;

/**
 * 日志初始化
 * @author qing
 *
 */
public class Log4jConfig {
	
	private static boolean isReload = true; 
	
    private static void load() {  
    	try {//包同级
    		Properties properties = MyResource.getJarProperties("log4j.properties");
    		//制定路径的文件
    		if(properties==null) {
    			properties = MyResource.getProperties( MyResource.getSrcProperties("app.properties").getProperty("log4j.path", "/opt/all_conf/log4j.properties"));
    			//程序包内
    			if(properties == null) {
    				properties = MyResource.getSrcProperties("log4j.properties");
    			}
    		}
    		PropertyConfigurator.configure(properties);
    	}catch (Exception e) {
    		e.printStackTrace();
		}
    }  
    
	public static void reload() {  
        if (isReload) {  
            load();  
        }  
        isReload = false;  
    }  
	
    public void setReload(boolean flag) {  
        isReload = flag;  
    }  
}
